# 作者：一只牛吗
# 2025 年01月 27日 04时 24分 03秒
# 1278599690@qq.com
class Gun:
    def __init__(self, model):
        self.model = model
        self.ammo = 0

    def add_ammo(self, num):
        print(f'{self.model} 装填 {num} 颗子弹！')
        self.ammo += num

    def shoot(self):
        if self.ammo > 0:
            print(f'{self.model} 发射子弹！, 剩余弹药 {self.ammo}')
            self.ammo -= 1
        else:
            print(f'{self.model} 无子弹！')


class Soldier:
    def __init__(self, name):
        self.name = name
        self.gun = None

    def set_gun(self, gun):
        self.gun = gun
        print(f'{self.name} 拿起 {gun.model} 枪！')

    def shoot(self):
        if self.gun == None:
            print(f'{self.name} 没有枪！')
        else:
            print('枪口对准了目标！')
            self.gun.shoot()


if __name__ == '__main__':
    gun = Gun('AK-47')
    soldier1 = Soldier('许三多')
    soldier1.shoot()
    soldier1.set_gun(gun)
    add_ammo = gun.add_ammo(3)
    soldier1.shoot()  # 许三多 发射子弹！
    soldier1.shoot()
    gun.add_ammo(10)
    soldier1.shoot()  # 许三多 发射子弹！
    soldier1.shoot()  # 许三多 发射子弹！
    soldier1.shoot()  # 许三多 发射子弹！
